<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>todolist</h2>
    <input type="text" id="input">
    <div id="app"></div>
    <script>
        var input = document.getElementById("input");
        var app =document.getElementById("app")
        var histors =[]
        // 获取输入框的值
        input.onkeydown =function(event){
            if(event.keyCode == 13){
                if(this.value !="" && histors.indexOf(this.value) ==-1){
                    var p =document.createElement("p");
                    p.innerHTML =this.value;
                    app.prepend(p);
                    histors.unshift(this.value)
                    this.value =""
                    console.log(histors);
                }else{
                    alert("输入的字段不能是空字符串或者相同的字段")
                }
            }
            var p = document.getElementsByTagName("p");
            for(var i=0;i<p.length;i++){
                p[i].onclick =function(){
                    this.style.display ="none"
                }
            }
        }
    </script>
</body>
</html>